package pers.amos.edu.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.amos.edu.pojo.School;
import pers.amos.edu.service.SchoolService;

import java.util.List;

/**
 * @author amos wong
 * @create 2020-02-01 19:09
 */

@RestController
@RequestMapping("/edu/school")
/**
 * 查询学校的接口
 */
@Api(tags = "查询学校的接口")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    /**
     * 根据地区分页查询所有的学校
     *
     * @param region 用户所选择的地区(需要传递中文 比如：北京）
     * @return
     */
    @ApiOperation("根据地区查询学校")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "region", value = "学校所属地区"),
            @ApiImplicitParam(name = "openId", value = "可以不传openId")})
    @GetMapping
    public ResponseEntity<List<School>> getSchoolList(String region, @RequestParam(value = "openId", required = false) String openId) {
        return ResponseEntity.ok(schoolService.getSchoolList(region, openId));
    }

    /**
     * 搜素功能
     * @param name 用户搜素的学校名称
     * @return
     */
    @ApiOperation("搜索学校的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "学校的名称"),
            @ApiImplicitParam(name = "openId", value = "可以不传openId")})
    @GetMapping("/search")
    public ResponseEntity<List<School>> searchSchoolByPage(String name, @RequestParam(value = "openId", required = false) String openId) {
        return ResponseEntity.ok(schoolService.searchSchool(name, openId));
    }
}
